package acwing._2LanQiao._2BinarySearch_PrefixSum;

import java.util.Scanner;

/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._2BinarySearch_PrefixSum
 * @File : Q0730.java
 * @Author : WangRuoyu
 * @Date : 2023/3/13 16:31
 */

public class Q0730 {
    static int[] q;

    static boolean check(int mid) {
        int e = mid;
        for (int i = 0; i < q.length; ++i) {
            e = 2 * e - q[i];
            if (e < 0) {
                return false;
            }
            if (e > 1e5) {
                return true;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        q = new int[n];
        for (int i = 0; i < q.length; i++) {
            q[i] = scan.nextInt();
        }
        int l = 1;
        int r = 100010;

        while (l < r) {
            int mid = (r + l) / 2;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        System.out.println(l);
    }
}
//5
//3 4 3 2 4